package com.ruoyi.project.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.project.business.service.IPaperService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.business.domain.Paper;
import com.ruoyi.project.business.service.IPaperService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 试卷Controller
 *
 * @author hongwj
 * @date 2024-10-22
 */
@RestController
@RequestMapping("/business/paper" )
@Slf4j
public class PaperController extends BaseController {
    @Autowired
    private IPaperService paperService;

    /**
     * 查询试卷列表
     */
    //@PreAuthorize("@ss.hasPermi('business:paper:list')" )
    @GetMapping("/list" )
    public TableDataInfo list(Paper paper) {
        startPage();
        List<Paper> list = paperService.selectPaperList(paper);
        return getDataTable(list);
    }

    /**
     * 查询所有试卷列表
     */
    //@PreAuthorize("@ss.hasPermi('business:paper:all')" )
    @Log(title = "试卷" , businessType = BusinessType.OTHER)
    @GetMapping("/all/papers" )
    public AjaxResult all(Paper paper) {
        List<Paper> list = paperService.selectPaperList(paper);
        return success(list);
    }

    /**
     * 导出试卷列表
     */
    //@PreAuthorize("@ss.hasPermi('business:paper:export')" )
    @Log(title = "试卷" , businessType = BusinessType.EXPORT)
    @PostMapping("/export" )
    public void export(HttpServletResponse response, Paper paper) {
        List<Paper> list = paperService.selectPaperList(paper);
        ExcelUtil<Paper> util = new ExcelUtil<Paper>(Paper. class);
        util.exportExcel(response, list, "试卷数据" );
    }

    /**
     * 获取试卷详细信息
     */
    //@PreAuthorize("@ss.hasPermi('business:paper:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) Long id) {
        return success(paperService.selectPaperById(id));
    }

    /**
     * 新增试卷
     */
    //@PreAuthorize("@ss.hasPermi('business:paper:add')" )
    @Log(title = "试卷" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Paper paper) {
        return toAjax(paperService.insertPaper(paper));
    }

    /**
     * 修改试卷
     */
    //@PreAuthorize("@ss.hasPermi('business:paper:edit')" )
    @Log(title = "试卷" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Paper paper) {
        return toAjax(paperService.updatePaper(paper));
    }

    /**
     * 删除试卷
     */
    //@PreAuthorize("@ss.hasPermi('business:paper:remove')" )
    @Log(title = "试卷" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(paperService.deletePaperByIds(ids));
    }
}
